<?php
/**
 * 自定义表头
 * User: xiadx
 * Date: 2017/06/09
 * Time: 18:21
 * Version:9.0.0.0
 */
class GetCustomTitleByZhuyuanIdController extends Yaf_Controller_Abstract
{
    public function IndexAction()
    {
        $request = $this->getRequest();
        $zhuyuan_id = $request->getPost("zhuyuan_id","");
        $user_department = $request->getPost("user_department","");
        $type = $request->getPost("type","");  // 表单名称
        $yiyuan_id = $request->getPost("yiyuan_id","");

        //医院id判断
        if($yiyuan_id === "")
        {
            Utility::apiJsonError(20028, '请输入医院ID');
        }
        elseif(!ctype_digit("$yiyuan_id"))
        {
            Utility::apiJsonError(20027, '医院ID必须是整型');
        }


        if($zhuyuan_id === "")
        {
            Utility::apiJsonError(20128, 'zhuyuan_id IS NOT NULL');
        }
        if ($type == '') {
            Utility::apiJsonError(20129, '表单名称不能为空！');
        }

        $hulicol_result = DB::select('hulicol_name')
                ->from('data_hulijilu_template')
                ->where('xiangmu_leixing', '=', 'customTitle')
                ->and_where('biaodan_name', '=', $type)
                ->and_where_open()
                    ->where('keshi', '=', '通用')
                    ->or_where('keshi', '=', $user_department)
                ->and_where_close()
                ->execute()
                ->as_array();
        // 获取该患者的护理记录单中已经录入了自定义表头的护理项
        $huli_col_name_arr = array();
        foreach ($hulicol_result as $val) {
            $custom_title_name = DB::select($val[hulicol_name])
                                    ->from('zhuyuan_huli_wenshu_detail')
                                    ->where('zhuyuan_id', '=', $zhuyuan_id)
                                    ->and_where($val[hulicol_name], '!=', '')
                                    ->and_where('deleted_at', 'IS', NULL)
                                    ->execute()
                                    ->get($val[hulicol_name]);
            $custom_title_name = explode('|', $custom_title_name)[0];
            $huli_col_name_arr[$val['hulicol_name']] = $custom_title_name;
        }
        // end
        $statr['staus'] = 200;
        $statr['msg'] = "数据同步成功";
        $statr['result'] = $huli_col_name_arr;
        Utility::apiJsonResultExtends($statr);
    }
}
